<script>
	export default {
		onLaunch: function() {
			console.log('App Launch');
			
				let data = uni.getStorageSync('data');
				if(data != ''){
					uni.request({
					    url: this.$store.state.ip + 'authorization/oauth/token', //仅为示例，并非真实接口地址。
					    data: {
							"grant_type":"refresh_token",
							"client_secret":"test_secret",
							"client_id":"test_client",
							"refresh_token":data.refreshToken,
					    },
						method:'POST',
						dataType:'json',
					    header: {
					        'Authorization': 'Basic dGVzdF9jbGllbnQ6dGVzdF9zZWNyZXQ=', //自定义请求头信息
							'content-type': 'application/x-www-form-urlencoded'
					    },
					    success: (res) => {
							this.$store.commit('login',{'username':data.username,'token':res.data.data.token,'refreshToken':res.data.data.refreshToken});
							// uni.setStorage({
							//     key: 'token',
							//     data: res.data.data.token,
							//     success: function () {
							//         console.log('success');
							//     }
							// });
							// localStorage.setItem("token",res.access_token);
							// localStorage.setItem("refresh_token",res.refresh_token);
							// localStorage.setItem("username",self.username);
							//self.$router.push('/');
					    }
					});
				}
				
			
		},
		onShow: function() {
			console.log('App Show');
		},
		onHide: function() {
			console.log('App Hide');
		}
	}
</script>

<style>
	/* 头条小程序需要把 iconfont 样式放到组件外 */
	@import "components/m-icon/m-icon.css";

	/*每个页面公共css */
	page {
		min-height: 100%;
		display: flex;
		font-size: 16px;
	}
	map{
		height: 100%!important;
	}
	/* #ifdef MP-BAIDU */
	page {
		width: 100%;
		height: 100%;
		display: block;
	}

	swan-template {
		width: 100%;
		min-height: 100%;
		display: flex;
	}

	/* 原生组件模式下需要注意组件外部样式 */
	custom-component {
		width: 100%;
		min-height: 100%;
		display: flex;
	}

	/* #endif */

	/* #ifdef MP-ALIPAY */
	page {
		min-height: 100vh;
	}

	/* #endif */

	/* 原生组件模式下需要注意组件外部样式 */
	m-input {
		width: 100%;
		/* min-height: 100%; */
		display: flex;
		flex: 1;
	}

	.content {
		display: flex;
		flex: 1;
		flex-direction: column;
		background-color: #efeff4;
		padding: 10px;
	}

	.input-group {
		background-color: #ffffff;
		margin-top: 20px;
		position: relative;
	}

	.input-group::before {
		position: absolute;
		right: 0;
		top: 0;
		left: 0;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}

	.input-group::after {
		position: absolute;
		right: 0;
		bottom: 0;
		left: 0;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}

	.input-row {
		display: flex;
		flex-direction: row;
		position: relative;
		font-size: 18px;
		line-height: 40px;
	}

	.input-row .title {
		width: 72px;
		padding-left: 15px;
	}

	.input-row.border::after {
		position: absolute;
		right: 0;
		bottom: 0;
		left: 8px;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc;
	}

	.btn-row {
		margin-top: 25px;
		padding: 10px;
	}

	button.primary {
		background-color: #0faeff;
	}
</style>
